import api from './request'

/**
 * 入院登记和患者管理相关API
 */

// 新增被保险人(患者入院登记) - 主键ID由数据库自增生成
export const addInsuredPerson = (data) => {
  return api.post('/insured_person/add', data)
}

// 修改被保险人信息 - 用于后续编辑功能
export const updateInsuredPerson = (data) => {
  return api.put('/insured_person/update', data)
}

// 根据ID查询被保险人信息
export const getInsuredPersonById = (id) => {
  return api.get(`/insured_person/${id}`)
}

// 分页查询被保险人列表
export const pageQueryInsuredPerson = (data) => {
  return api.post('/insured_person/page', data)
}

// 删除被保险人
export const deleteInsuredPerson = (id) => {
  return api.delete(`/insured_person/${id}`)
}

// 根据患者ID查询医保报销比例
export const getReimbursementRatio = (patientId) => {
  return api.get(`/insured_person/reimbursement/${patientId}`)
}

// 根据医院等级、人员类型和费用金额查询医保报销比例
export const getReimbursementRatioByParams = (params) => {
  return api.get('/insured_person/reimbursement/ratio', { params })
}

/**
 * 患者疾病管理API
 */

// 根据患者ID查询疾病列表
export const getPatientDiseases = (patientId) => {
  return api.get(`/patient_disease/patient/${patientId}`)
}

// 新增患者疾病关联
export const addPatientDisease = (data) => {
  return api.post('/patient_disease/add', data)
}

// 修改患者疾病关联
export const updatePatientDisease = (data) => {
  return api.put('/patient_disease/update', data)
}

// 删除患者疾病关联
export const deletePatientDisease = (id) => {
  return api.delete(`/patient_disease/${id}`)
}

// 分页查询患者疾病关联
export const pageQueryPatientDisease = (data) => {
  return api.post('/patient_disease/page', data)
}

/**
 * 疾病查询API
 */

// 根据名称查询疾病列表
export const searchDiseasesByName = (name) => {
  return api.get('/disease_diagnosis/list', { params: { name } })
}

// 分页查询疾病
export const pageQueryDiseases = (data) => {
  return api.post('/disease_diagnosis/page', data)
}

// 根据ID查询疾病详情
export const getDiseaseById = (id) => {
  return api.get(`/disease_diagnosis/${id}`)
}

/**
 * 患者医嘱管理API
 */

// 患者药品处方医嘱
export const getPatientDrugOrders = (patientId) => {
  return api.get(`/patient_drug_order/patient/${patientId}`)
}

export const addPatientDrugOrder = (data) => {
  return api.post('/patient_drug_order/add', data)
}

export const updatePatientDrugOrder = (data) => {
  return api.put('/patient_drug_order/update', data)
}

export const deletePatientDrugOrder = (id) => {
  return api.delete(`/patient_drug_order/${id}`)
}

export const pageQueryPatientDrugOrders = (data) => {
  return api.post('/patient_drug_order/page', data)
}

// 患者诊疗项目医嘱
export const getPatientServiceOrders = (patientId) => {
  return api.get(`/patient_service_order/patient/${patientId}`)
}

export const addPatientServiceOrder = (data) => {
  return api.post('/patient_service_order/add', data)
}

export const updatePatientServiceOrder = (data) => {
  return api.put('/patient_service_order/update', data)
}

export const deletePatientServiceOrder = (id) => {
  return api.delete(`/patient_service_order/${id}`)
}

export const pageQueryPatientServiceOrders = (data) => {
  return api.post('/patient_service_order/page', data)
}

// 患者医疗服务医嘱
export const getPatientServiceItemOrders = (patientId) => {
  return api.get(`/patient_treatment_order/patient/${patientId}`)
}

export const addPatientServiceItemOrder = (data) => {
  return api.post('/patient_treatment_order/add', data)
}

export const updatePatientServiceItemOrder = (data) => {
  return api.put('/patient_treatment_order/update', data)
}

export const deletePatientServiceItemOrder = (id) => {
  return api.delete(`/patient_treatment_order/${id}`)
}

export const pageQueryPatientServiceItemOrders = (data) => {
  return api.post('/patient_service_items_order/page', data)
}

// 搜索药品
export const searchDrugsByName = (name) => {
  return api.get('/drugs_info/search', { params: { name } })
}

export const pageQueryDrugs = (data) => {
  return api.post('/drugs_info/page', data)
}

// 搜索诊疗项目
export const searchMedicalServicesByName = (name) => {
  return api.get('/medical_services/search', { params: { name } })
}

export const pageQueryMedicalServices = (data) => {
  return api.post('/medical_services/page', data)
}

// 搜索医疗服务项目
export const searchMedicalServiceItemsByName = (name) => {
  return api.get('/medical_service_items/search', { params: { name } })
}

export const pageQueryMedicalServiceItems = (data) => {
  return api.post('/medical_service_items/page', data)
}
